function eyetrackerClassification(subject, toilim, className, condition)
    % Performs classification on eyetracker and EOG data. This should
    % perform at chance level. Returns performance and p-values for
    % classification on eyetracker and EOG data, for any toi specified
    % Displays a warning if classification performance on eyetracker or EOG
    % data seems to good. This warning stays until a key is pressed to
    % continue. Also, it returns structs containing the performance and
    % p-value of classification on eyetracker and EOG data for each
    % combination of classes. 
    % 
    % subject: struct with subject-specific information. Should at least
    % contain the fields subjID, subjectDir, allChannels (all channels but
    % the ones rejected) and noWords (0 when the task includes the word-category, 
    % 1 when the task doesn't contain this category).
    % toilim: time window of interest.
    % className: cell array containing names of all classes that can be in
    % the task. (Expects the word-class to be included as the last one,
    % even though it isn't always present).
    %
    % Note: contains some code duplication with sensorLevelClassification.
    % May want to integrate it there.
    
    pause on;

    eval(['load ', subject.subjectDir, '/', subject.subjID, '_', condition, '_data.mat data;']);

    % prepare data
    cfg = [];
    cfg.toilim = toilim;
    data_segmented = ft_redefinetrial(cfg, data);


    % sort trialtypes (not before segmentation, as trials may get lost)
    [faceTrl sceneTrl bodyTrl toolTrl wordTrl] = deal([]);

    if strcmp(subject.subjID, 'P01')
        for i = 1 : length(data_segmented.trialinfo)
            if data_segmented.trialinfo(i) == 201 %faces
                faceTrl = [faceTrl i];
            elseif data_segmented.trialinfo(i) == 202 %scenes
                sceneTrl = [sceneTrl i];
            elseif data_segmented.trialinfo(i) == 203 %bodies
                bodyTrl = [bodyTrl i];
            elseif data_segmented.trialinfo(i) == 204 %tools
                toolTrl = [toolTrl i];
            elseif data_segmented.trialinfo(i) == 205 %words
                wordTrl = [wordTrl i];
            else
                error('ERROR: Invalid category trigger code.');
            end
        end
    else
        if strcmp(condition, 'noCond') || strcmp(condition, 'lum_spat')
            for i = 1 : length(data_segmented.trialinfo)
                if data_segmented.trialinfo(i) == 21 %faces
                    faceTrl = [faceTrl i];
                elseif data_segmented.trialinfo(i) == 22 %scenes
                    sceneTrl = [sceneTrl i];
                elseif data_segmented.trialinfo(i) == 23 %bodies
                    bodyTrl = [bodyTrl i];
                elseif data_segmented.trialinfo(i) == 24 %tools
                    toolTrl = [toolTrl i];
                elseif data_segmented.trialinfo(i) == 25 %words
                    wordTrl = [wordTrl i];
                else
                    error('ERROR: Invalid category trigger code.');
                end
            end
        elseif strcmp(condition, 'lum')
            for i = 1 : length(data_segmented.trialinfo)
                if data_segmented.trialinfo(i) == 31 %faces
                    faceTrl = [faceTrl i];
                elseif data_segmented.trialinfo(i) == 32 %scenes
                    sceneTrl = [sceneTrl i];
                elseif data_segmented.trialinfo(i) == 33 %bodies
                    bodyTrl = [bodyTrl i];
                elseif data_segmented.trialinfo(i) == 34 %tools
                    toolTrl = [toolTrl i];
                elseif data_segmented.trialinfo(i) == 35 %words
                    wordTrl = [wordTrl i];
                else
                    error('ERROR: Invalid category trigger code.');
                end
            end
        else
            error('ERROR: Unknown condition identifier. Please specify ''lum'' or ''lum_spat''');
        end
    end

    %loop over all class combinations
    startClass = 2;
    for i = 1:length(className) - 1 - subject.noWords
        for j= startClass:length(className) - subject.noWords
                
                class1 = className{i};
                class2 = className{j};
                
                %feed eyetracker data into classifier
                cfg             = [];
                cfg.parameter   = 'trial';
                cfg.keeptrials  = 'yes';
                cfg.channel     = subject.allChannels;

                eval(['cfg.trials = ', class1, 'Trl;']);
                cond1data       = ft_timelockanalysis(cfg, data_segmented);

                eval(['cfg.trials = ', class2, 'Trl;']);
                cond2data       = ft_timelockanalysis(cfg, data_segmented);

                % cross-validation
                cfg             = [];
                cfg.layout      = 'CTF275.lay';
                cfg.method      = 'crossvalidate';
                cfg.channel     = {'UADC005', 'UADC006', 'UADC007'};
                %cfg.mva         = {ft_mv_standardizer ft_mv_svm};
                cfg.mva         = {ft_mv_standardizer ft_mv_glmnet('lambda',0.01)}; %old lambda 0.01, best lambda 0.0005
                cfg.design      = [ones(length(cond1data.trialinfo),1); 2*ones(length(cond2data.trialinfo),1)];
                eval(['tstat_', class1,'_', class2,' = ft_timelockstatistics(cfg,cond1data,cond2data);']);


                eval(['eyetracker.', class1, '_', class2, '.perf = tstat_', class1, '_', class2, '.performance;']);
                eval(['eyetracker.', class1, '_', class2, '.pval = tstat_', class1, '_', class2, '.pvalue;']);

                %Throw warnings if the performance is too good or the
                %p-value to small
                if eval(['eyetracker.', class1, '_', class2, '.perf > 0.6 || eyetracker.', class1, '_', class2, '.pval <0.1'])
                    display(sprintf('\nWARNING: Suspiciously high classification performance on eyetracker data on time interval %i to %i for %s vs %s.', min(toilim), max(toilim), class1, class2));
                    eval(['display(sprintf(''Performance is %i, p-value is %i'', eyetracker.', class1, '_', class2, '.perf, eyetracker.', class1, '_', class2, '.pval));']);
                    pause
                end
                
                %as some extra sanity check, also feed EOG data into classifier
                cfg.channel = {'EEG057', 'EEG058'};
                eval(['tstat_', class1,'_', class2,' = ft_timelockstatistics(cfg,cond1data,cond2data);']);

                eval(['EOG.', class1, '_', class2, '.perf = tstat_', class1, '_', class2, '.performance;']);
                eval(['EOG.', class1, '_', class2, '.pval = tstat_', class1, '_', class2, '.pvalue;']);
                
                %Throw warnings if the performance is too good or the
                %p-value to small
                if eval(['EOG.', class1, '_', class2, '.perf > 0.6 || EOG.', class1, '_', class2, '.pval <0.1'])
                    display(sprintf('nWARNING: Suspiciously high classification performance on EOG data on time interval %i to %i for %s vs %s.', min(toilim), max(toilim), class1, class2));
                    eval(['display(sprintf(''Performance is %i, p-value is %i'', EOG.', class1, '_', class2, '.perf, EOG.', class1, '_', class2, '.pval));']);
                    pause
                end
        end
        startClass = startClass + 1;
    end
    
    save([subject.subjectDir, '/', subject.subjID, '_', condition, '_eyetrackerClassification_toi_', num2str(min(toilim)), '-', num2str(max(toilim)), '.mat'], 'eyetracker', 'EOG', '-v7.3') 
end